package ebj.common.consistenthash;

import java.nio.charset.Charset;
import java.util.List;

import com.google.common.collect.Lists;
import com.google.common.hash.Hashing;

public class ConsistentHashTest {
	public static void main(String[] args) {
		List<String> server = Lists.newArrayList("a", "b", "c"); // 三台服务器

		String[] keyArray = { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg",
				"hhh" }; // 八个key值
		for (String key : keyArray) {
			int bucket = Hashing.consistentHash(
					Hashing.md5().hashString(key, Charset.forName("utf-8")),
					server.size());
			String serverName = server.get(bucket);
			System.out.println(key + " >> server is: " + serverName);
		}
	}
}
